//
//  SelectActionManger.swift
//  Exchange
//
//  Created by 孟祥群 on 2018/4/28.
//  Copyright © 2018年 common. All rights reserved.
//

import UIKit
enum sheetStyle {
    case commonSty //通用筛选框
    case selectionStyle //筛选框
    case leverSelectStyle// 杠杆委托筛选框
    case capitalStyle //资金明细
    case capitalAllStyle//资金明细全部数据
    case leverStyle //杠杆设置
    
}
protocol SelectmangerDelegate: class {
    func selectModel(model:SheetModel)
}
class SelectActionManger: NSObject {
    var select:SelectBaseSheet?
    static let manager = SelectActionManger()
    
    func creatSheet(style:sheetStyle, titleArr:[String] = [],selectStr:String? = nil ,dataSource:SelectmangerDelegate) {
        switch style {
        case .commonSty:
            let model = CommonSheetModel(style: style)
            let config = ComonConfig(style: style)
            select =  ComonSheet(model:model,coinfig:config,titleArr: titleArr, selectStr: selectStr, dataSource: dataSource)
            break
        case .selectionStyle:
            let model = SelectionModel(style: style)
            let config = SelectionConfig(style: style)
           select = SelectionSheet(model: model, coinfig: config, dataSource: dataSource)
            break
        case .leverSelectStyle:
            let model = SelectionModel(style: style)
            let config = SelectionConfig(style: style)
            select = SelectionSheet(model: model, coinfig: config, dataSource: dataSource)
            break
        case .capitalStyle:
            let model = CapitalModel(style: style)
            let config = CapitalConfig(style: style)
            select = CapitalSheet(model: model, coinfig: config,selectStr:selectStr, dataSource: dataSource)
            break
        case .capitalAllStyle:
            let model = CapitalModel(style: style)
            let config = CapitalConfig(style: style)
            select = CapitalSheet(model: model, coinfig: config,selectStr:selectStr, dataSource: dataSource)
            break
        case .leverStyle:
            let model = LeverCapitalModel(style: style)
            let config = LeverConfig(style: style)
            select = LeverSheet(model: model, coinfig: config, dataSource: dataSource)
            break
     }
        select?.showSheet()
  }
    
    func creatLeverSheet(model:LeverTradeModel,dataSource:SelectmangerDelegate)  {
        let leverModel = LeverCapitalModel(style: .leverStyle)
        let config = LeverConfig(style: .leverStyle)
        select = LeverSheet(model: leverModel, coinfig: config, dataSource: dataSource)
        (select as? LeverSheet)?.leverRefresh(model: model)
    }
    
    func close() -> Void {
        select?.close()
        select?.removeFromSuperview()
        select?.backView?.removeFromSuperview()
        select = nil
    }
}
